package com.wzz.controller;

import com.wzz.pojo.Person;
import com.wzz.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/CIMS")
public class PersonController {

    @Autowired
    private PersonService personService;

    //根据id倒叙获取全部员工
    @GetMapping("/getAllPerson")
    public Map<String,Object> getAllPerson(){
        List<Person> persons = personService.getAllPerson();
        HashMap<String,Object> map=new HashMap<>();
        if (persons!=null){
            map.put("code",001);
            map.put("msg","成功");
            map.put("data",persons);
        }else{
            map.put("code",002);
            map.put("msg","未查询到员工");
            map.put("data",null);
        }
        return map;
    }

    //添加员工
    @GetMapping("/addPerson")
    public Map<String,Object> addPerson(Person person){
        System.out.println(person);
        int num = personService.addPerson(person);
        HashMap<String,Object> map=new HashMap<>();
        if (num!=0){
            map.put("code",003);
            map.put("msg","成功");
        }else{
            map.put("code",002);
            map.put("msg","失败");
        }
        return map;
    }

    //删除员工
    @GetMapping("/delPerson")
    public Map<String,Object> delPerson(int id){
        HashMap<String,Object> map=new HashMap<>();
        int num = personService.delPerson(id);
        if (num!=0){
            map.put("code",003);
            map.put("msg","成功");
        }else{
            map.put("code",002);
            map.put("msg","失败");
        }
        return map;
    }
}
